function loginOnNickLoginButtonClick() {
    var user = $('#user-input-nick').val();
    var pwd = $('#password-input-nick').val();

    if (user == '' || pwd == '') {
        Swal.fire({
            type: 'error',
            title: '用户名或者密码不能为空'
        });
        return;
    }
    else {
        var str = JSON.stringify({"account": user, "password": pwd});
        var key = makeKey(16);
        var encrypted = CryptoJS.AES.encrypt(str, key).toString();

        var encrypt = new JSEncrypt();
        encrypt.setPublicKey(publicKey);
        key = encrypt.encrypt(key);

        $.ajax(
            {
                type: 'post',
                async: true,
                data: {'account': encrypted, 'key': key},
                url: document.location.origin + '/api/userlogincheck?param=nick',
                dataType:'text',
                success: function(data) {
                    var json = JSON.parse(data);

                    if (json.result == 200) {
                        setCookie("token", json.token, 30);
                        var previousPage = getCookie("pagebeforelogin");
                        if (previousPage == null || previousPage == '') {
                            previousPage = "/rankpage/zonghe/0";
                        }

                        var uri = document.location.origin + previousPage;
                        window.location.href = uri;
                    }
                    else {
                        deleteCookie("token");
                        Swal.fire({
                            type: 'error',
                            title: json.description
                        });
                    }
                },
                error: function () {
                    console.log("Ajax 发生错误！");
                }
            }
        );
    }
}

function loginOnEmailLoginButtonClick() {
    var user = $('#user-input-email').val();
    var pwd = $('#password-input-email').val();

    if (user == '' || pwd == '') {
        Swal.fire({
            type: 'error',
            title: '邮件或者密码不能为空'
        });
        return;
    }
    else {
        var str = JSON.stringify({"account": user, "password": pwd});
        var key = makeKey(16);
        var encrypted = CryptoJS.AES.encrypt(str, key).toString();

        var encrypt = new JSEncrypt();
        encrypt.setPublicKey(publicKey);
        key = encrypt.encrypt(key);

        $.ajax(
            {
                type: 'post',
                async: true,
                data: {'account': encrypted, 'key': key},
                url: document.location.origin + '/api/userlogincheck?param=email',
                dataType:'text',
                success: function(data) {
                    var json = JSON.parse(data);

                    if (json.result == 200) {
                        setCookie("token", json.token, 30);
                        var previousPage = getCookie("pagebeforelogin");
                        if (previousPage == null || previousPage == '') {
                            previousPage = "/rankpage/zonghe/0";
                        }

                        var uri = document.location.origin + previousPage;
                        window.location.href = uri;
                    }
                    else {
                        deleteCookie("token");
                        Swal.fire({
                            type: 'error',
                            title: json.description
                        });
                    }
                },
                error: function () {
                    console.log("Ajax 发生错误！");
                }
            }
        );
    }
}